package com.example.springback.controller;

import com.example.springback.common.Result;
import com.example.springback.domain.Employee;
import com.example.springback.service.EmployeeService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/employee")
public class EmployeeController {
    @Resource
    private EmployeeService employeeService;

    @GetMapping("/searchPage")
    public Result selectPage(Employee employee ,@RequestParam(defaultValue = "1") Integer pageNumber,@RequestParam(defaultValue = "5") Integer pageSize){
       PageInfo<Employee> employeePageInfo =employeeService.selectPage(employee,pageNumber,pageSize);
        return Result.success(employeePageInfo);
    }
//新增员工
    @PostMapping("/add")
    public Result add(@RequestBody Employee employee){
        employeeService.add(employee);
        return Result.success();
    }
    //更新员工信息
    @PostMapping ("/update")
    public Result update(@RequestBody Employee employee){
        employeeService.update(employee);
        return Result.success();
    }
    //删除员工信息
    @PostMapping ("/delete")
    public Result delete(@RequestBody Employee employee){
        employeeService.delete(employee.getEmployeeId(),employee.getEnterpriseId());
        return Result.success();
    }
    @PostMapping("/retire")
    public Result retire(@RequestBody Employee employee){
        employee.setIsleave(0);
        int people=employeeService.retire(employee);
        return Result.success(people);
    }
    @PostMapping("/deletebatch")
    public Result deleteBatch(@RequestBody List<Employee> employeeList){
       employeeService.deleteBatch(employeeList);
       return Result.success();
    }

}
